import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent implements OnInit {
  title = 'app';

  ngOnInit(): void {
    const observable = new Observable((observer: any) => {
      observer.next('hello!');
      observer.next('world!');
      observer.complete();
      observer.next('not render');
    });

    const subscription = observable.subscribe(
      (res) => {
        console.log(res);
      },
      (err) => {
        console.log(err);
      },
      () => {
        console.log('Completed');
      }
    );

    setTimeout(() => {
      console.log('unsubscribe');
      subscription.unsubscribe();
    }, 2000);
  }
}
